package nowcoder;
/**
 * 58541-进制转换
 * https://www.nowcoder.com/practice/ac61207721a34b74b06597fe6eb67c52?tpId=85&&tqId=29862&rp=1&ru=/activity/oj&qru=/ta/2017test/question-ranking
 */
import java.util.*;
public class Day04_2 {
    public static void main(String[] args) {
        Scanner input = new Scanner(System.in);
        long m = input.nextLong();
        int n = input.nextInt();

        // 将表示n进制的字符存入数组中
        char[] s = new char[n];
        for (int i = 0; i < s.length; i++) {
            if(i < 10){
                s[i] = (char) (48 + i);
            }else{
                s[i] = (char) (65 + i - 10);
            }
        }

        StringBuilder sb = new StringBuilder();
        while(m > 0){
            int num = (int) (m % n);
            sb.append(s[num]);
            m /= n;
        }

        System.out.println(sb.reverse().toString());
    }
}
